package com.yzcrm.erp.crm.common;

import cn.hutool.core.util.ObjectUtil;

public enum CrmEnum {
    /**
     * CRM Enum
     * 注释：叫这个名字不太合适应该叫LebelEnum，label后续扩展了进销存和财务等realm，改名字的话变更比较多。。。 暂用
     */
    CRM_LEADS("crm_leads", 1, "潜在客户", "NULL", ""),
    CRM_CUSTOMER("crm_customer", 2, "目标客户", "NULL", ""),
    CRM_CONTACTS("crm_contacts", 3, "联系人", "NULL", ""),
    CRM_PRODUCT("crm_product", 4, "产品", "NULL", ""),
    CRM_BUSINESS("crm_business", 5, "商机", "NULL", ""),
    CRM_CONTRACT("crm_contract", 6, "合同", "YZHT", ""),
    CRM_RECEIVABLES("crm_receivables", 7, "回款", "YZHK", ""),
    CRM_RECEIVABLES_PLAN("crm_receivables_plan", 8, "回款计划", "NULL", ""),
    CRM_CUSTOMER_POOL("crm_customer_pool", 9, "客户公海", "NULL", ""),
    CRM_PRE_SALES("crm_preSales", 11, "售前申请", "NULL", ""),
    ADMIN_RECORD("admin_record", 12, "跟进记录", "NULL", ""),
    // 报价模板 type 730 开始
    CRM_QUOTATION_ITEM("crm_quotation_item", 731, "报价项模板", "NULL", ""),

    // 报价列表 type 750 开始
    CRM_QUOTATION_COMBINATION("crm_quotation_combination", 750, "报价列表", "NULL", ""),
//    PSI_SALES_ENTER("psi_salesEnter",20,"销售退货","NULL"),
//    PSI_RETRUN_ENTER("psi_retrunEnter",21,"归还入库","NULL"),
//    PSI_REPAIR_ENTER("psi_repairEnter",22,"维修入库","NULL"),
//    PSI_TEST_ENTER("psi_testEnter",23,"内部测试入库","NULL"),
//    PSI_INVENTORY_PROFIT_ENTER("psi_inventoryProfitEnter",24,"盘盈","NULL"),
//    PSI_OTHER_ENTER("psi_otherEnter",25,"其它入库","NULL"),
//    PSI_PURCHASE_ENTER("psi_purchaseEnter",30,"采购入库","NULL"),
//    PSI_SALES_LEAVE("psi_salesLeave",40,"销售出库","NULL"),
//    PSI_BORROW_LEAVE("psi_borrowLeave",41,"借用出库","NULL"),
//    PSI_REPAIR_LEAVE("psi_repairLeave",42,"维修出库","NULL"),
//    PSI_TEST_LEAVE("psi_testLeave",43,"内部测试出库","NULL"),
//    PSI_INVENTORY_LOSS_LEAVE("psi_inventoryLossLeave",44,"盘亏出库","NULL"),
//    PSI_OTHER_LEAVE("psi_otherLeave",45,"其它出库","NULL"),
    /**
     * 枚举值
     * 20-39 入库
     * 40-49 出库
     */
    PSI_SALES_ENTER("psi_enter_leave_stock",20,"销售退货","NULL", "psi_salesEnter"),
    PSI_RETRUN_ENTER("psi_enter_leave_stock",21,"归还入库","NULL", "psi_retrunEnter"),
    PSI_REPAIR_ENTER("psi_enter_leave_stock",22,"维修入库","NULL", "psi_repairEnter"),
    PSI_TEST_ENTER("psi_enter_leave_stock",23,"内部测试入库","NULL", "psi_testEnter"),
    PSI_INVENTORY_PROFIT_ENTER("psi_enter_leave_stock",24,"盘盈","NULL", "psi_inventoryProfitEnter"),
    PSI_OTHER_ENTER("psi_enter_leave_stock",25,"其它入库","NULL", "psi_otherEnter"),
    PSI_PURCHASE_ENTER("psi_enter_leave_stock",30,"采购入库","NULL", "psi_purchaseEnter"),
    PSI_SALES_LEAVE("psi_enter_leave_stock",40,"销售出库","NULL", "psi_salesLeave"),
    PSI_BORROW_LEAVE("psi_enter_leave_stock",41,"借用出库","NULL", "psi_borrowLeave"),
    PSI_REPAIR_LEAVE("psi_enter_leave_stock",42,"维修出库","NULL", "psi_repairLeave"),
    PSI_TEST_LEAVE("psi_enter_leave_stock",43,"内部测试出库","NULL", "psi_testLeave"),
    PSI_INVENTORY_LOSS_LEAVE("psi_enter_leave_stock",44,"盘亏","NULL", "psi_inventoryLossLeave"),
    PSI_OTHER_LEAVE("psi_enter_leave_stock",45,"其它出库","NULL", "psi_otherLeave"),
    PSI_STOREHOUSE("psi_storehouse",61,"仓库","NULL", ""),
    PSI_PRODUCT("crm_product",62,"产品","NULL", "psi_product"),
    PSI_QUERY_STOREHOUSE("crm_product",63,"在库查询","NULL", ""),


    FINANCE_SUPPLIER("finance_supplier",60,"供货商","NULL", ""),
    FINANCE_PURCHASE("finance_purchase",50,"采购","NULL", ""),
    FINANCE_OFFICE_PURCHASE("finance_purchase",51,"办公用品","NULL", "finance_officePurchase"),
    FINANCE_NORMAL_PURCHASE("finance_purchase",52,"常规备货","NULL", "finance_normalPurchase"),
    FINANCE_PROJECT_PURCHASE("finance_purchase",53,"项目备货","NULL", "finance_projectPurchase"),
    FINANCE_DEV_PURCHASE("finance_purchase",54,"研发用品","NULL", "finance_devPurchase"),
    FINANCE_OTHER_PURCHASE("finance_purchase",55,"其它","NULL", "finance_otherPurchase"),

    KMS_FILE("kms_file",100,"知识文件","NULL", ""),
    KMS_RESOURCE("kms_resource",101,"资源","NULL", ""),
    KMS_COURSE("kms_course",102,"课程","NULL", ""),
    KMS_BBS("kms_bbs",103,"论坛","NULL", ""),


    CRM_NULL("NULL",0,"NULL","NULL", "NULL")
    ;

    private final String name;
    private final String subName; // 对应出入库添加，出入库下分多种方式
    private final int type;
    private final String remarks;
    private final String num; //编码前缀

    CrmEnum(String name, int type, String remarks, String num, String subName) {
        this.name = name;
        this.type = type;
        this.remarks = remarks;
        this.num = num;
        this.subName = subName;
    }

    public static CrmEnum parse(int type) {
        for (CrmEnum Enum : CrmEnum.values()) {
            if (Enum.getType() == type) {
                return Enum;
            }
        }
        return CRM_NULL;
    }

    public static CrmEnum parse(String name) {

        if (ObjectUtil.isNull(name)) {
            return CRM_NULL;
        }

        // name查找
        for (CrmEnum Enum : CrmEnum.values()) {
            if (Enum.getName().equals(name)) {
                return Enum;
            }
        }

        // name没有查找到，查找subName
        for (CrmEnum Enum : CrmEnum.values()) {
            if (Enum.getSubName().equals(name)) {
                return Enum;
            }
        }

        return CRM_NULL;
    }

    public String getName() {
        return name;
    }

    public String getSubName() {
        return subName;
    }

    public int getType() {
        return type;
    }

    public String getRemarks() {
        return remarks;
    }

    public String getNum() {
        return num;
    }

}
